package org.baojie;

import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import org.baojie.server.refactor.DataBaseType;
import org.baojie.server.refactor.ParserState;
import org.baojie.server.refactor.SQLErrorType;
import org.baojie.server.refactor.parser.SQLParser;
import org.baojie.server.refactor.SourceDetail;
import org.baojie.server.refactor.visit.SQLVisitor;
import org.baojie.server.refactor.visit.Visitor;

import java.util.Map;

/**
 * @author baojie
 * @date 2022/6/14 下午6:45
 */
public class TestJSQLParser {

    public static final String oracle_create = "create table es_invc_hdr_temp(\n" +
            "      ID  VARCHAR2(15) NOT NULL,\n" +
            "      ORDER_KEY VARCHAR2(50) ,\n" +
            "      ORDER_REF_NO VARCHAR2(50) ,\n" +
            "      THIRD_PARTY_ORDER_ID VARCHAR2(100) ,\n" +
            "      STAT_CDE  VARCHAR2(20) CHECK (STAT_CDE in ('S','C','A','E')),\n" +
            "      REMARK   VARCHAR2(240), \n" +
            "      CREATE_DTE  DATE not null,          \n" +
            "      UPDATE_DTE DATE \n" +
            ");\n" +

            "ALTER TABLE es_invc_hdr_temp ADD CONSTRAINT constraint_name PRIMARY KEY (ID); "+

            "COMMENT ON TABLE es_invc_hdr_temp IS '发票信息临时表';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.ID IS '主键（⾃动⽣成）';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.ORDER_KEY IS '订单orderkey';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.ORDER_REF_NO IS 'Eshop订单编号';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.THIRD_PARTY_ORDER_ID IS '第三⽅订单编号';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.STAT_CDE IS '发票状态';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.REMARK IS '备注';\n" +
            "COMMENT ON COLUMN es_invc_hdr_temp.CREATE_DTE IS '创建时间（不能为空）';\n";//+
    //"COMMENT ON COLUMN es_invc_hdr_temp.UPDATE_DTE IS '更新时间';\n";

    public static void main(String args[]) throws Exception {
        SourceDetail detail = new SourceDetail();
        detail.setDataBaseType(DataBaseType.Oracle);
        SQLParser parser = SQLParser.getInstance();
        ParserState parserState = parser.parser(oracle_create, detail);
        parserState.classify();
        Visitor visitor = new SQLVisitor(parserState);
        Map<SQLErrorType, ColumnDefinition> error = visitor.visitCreate();
        System.out.println("ok");
    }


}
